<?php

require_once("lib/exception/internal_error_exception.php");
require_once("lib/exception/instance_not_found_exception.php");

require_once("lib/model/action.php");
require_once("model/autorfacade/util/util_autor.php");

require_once("model/autor_message/to/autor_message_to.php");
require_once("model/autor_message/dao/autor_message_dao_factory.php");

class change_message_to_new_action implements Action {

	private $number;
	
	public function __construct($number) {
		
		$this->number = $number;
	}
	
	public function do_execute() {
		try {
			$dao = Autor_message_dao_factory::singleton()->get_dao();
			$message = $dao->find_by_number($this->number);
			
			$message->set_state('new');
			$dao->update($message);
			
		}
		catch (Instance_not_found_exception $e) {
			throw new Model_exception($e);
		}
		catch (Internal_error_exception $e) {
			throw $e;
		}
		catch (Exception $e) {
			throw new Exception("Internal error exception --> " . $e);
		}
	}
	
}
?>
